<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>${message("admin.promotion.add")}</title>


    <link href="${base}/resources/admin/css/amazeui.css" rel="stylesheet" type="text/css" /><link href="${base}/resources/admin/css/common.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="${base}/resources/admin/js/jquery.js"></script>
    <script type="text/javascript" src="${base}/resources/admin/js/jquery.tools.js"></script>
    <script type="text/javascript" src="${base}/resources/admin/js/jquery.validate.js"></script>
    <script type="text/javascript" src="${base}/resources/admin/js/jquery.autocomplete.js"></script>
    <script type="text/javascript" src="${base}/resources/admin/editor/kindeditor.js"></script>
    <script type="text/javascript" src="${base}/resources/admin/js/common.js"></script>
    <script type="text/javascript" src="${base}/resources/admin/js/input.js"></script>
    <script type="text/javascript" src="${base}/resources/admin/datePicker/WdatePicker.js"></script>
    <style type="text/css">
        .memberRank label, .productCategory label, .brand label, .coupon label {
            min-width: 120px;
            _width: 120px;
            display: block;
            float: left;
            padding-right: 4px;
            _white-space: nowrap;
        }

    </style>
    <script type="text/javascript">
        $().ready(function() {

            var $inputForm = $("#inputForm");
            var $productTable = $("#productTable");
            var $productSelect = $("#productSelect");
            var $deleteProduct = $("a.deleteProduct");
            var $productTitle = $("#productTitle");
            var $giftTable = $("#giftTable");
            var $giftSelect = $("#giftSelect");
            var $deleteGift = $("a.deleteGift");
            var $giftTitle = $("#giftTitle");
            var productIds = [];
            var giftIds = [];
            var giftItemIndex = 0;

		[@flash_message /]

            // 商品选择
            $productSelect.autocomplete("product_select.htm", {
                dataType: "json",
                max: 20,
                width: 600,
                scrollHeight: 300,
                parse: function(data) {
                    return $.map(data, function(item) {
                        return {
                            data: item,
                            value: item.fullName
                        }
                    });
                },
                formatItem: function(item) {
                    if ($.inArray(item.id, productIds) < 0) {
                        return '<span title="' + item.fullName + '">' + item.fullName.substring(0, 50) + '<\/span>';
                    } else {
                        return false;
                    }
                }
            }).result(function(event, item) {
			[@compress single_line = true]
                var trHtml =
                        '<tr class="productTr">
                        <th>
                        <input type="hidden" name="productIds" value="' + item.id + '" \/>
                &nbsp;
                <\/th>
            <td>
            <span title="' + item.fullName + '">' + item.fullName.substring(0, 50) + '<\/span>
                <\/td>
            <td>
            <a href="javascript:;" class="deleteProduct"><i class="iconfont icon-shequshanchu del-icon" ></i><\/a>
                <\/td>
                <\/tr>';
			[/@compress]
                $productTitle.show();
                $productTable.append(trHtml);
                productIds.push(item.id);
                });

                // 删除商品
                $deleteProduct.live("click", function() {
                    var $this = $(this);
                    $.dialog({
                    type: "warn",
                    content: "${message("admin.dialog.deleteConfirm")}",
                    onOk: function() {
                    var id = parseInt($this.closest("tr").find("input:hidden").val());
                    productIds = $.grep(productIds, function(n, i) {
                    return n != id;
                });
                    $this.closest("tr").remove();
                    if ($productTable.find("tr.productTr").size() <= 0) {
                    $productTitle.hide();
                }
                }
                },260,180);
                });


                $.validator.addMethod("compare",
                function(value, element, param) {
                    var parameterValue = $(param).val();
                    if ($.trim(parameterValue) == "" || $.trim(value) == "") {
                    return true;
                }
                    try {
                    return parseFloat(parameterValue) <= parseFloat(value);
                } catch(e) {
                    return false;
                }
                },
                "${message("admin.promotion.compare")}"
                );

                $.validator.addClassRules({
                    giftItemQuantity: {
                    required: true,
                    integer: true,
                    min: 1
                }
                });

                // 表单验证
                $inputForm.validate({
                    rules: {
                    name: "required",
                    title: "required",
                    minimumPrice: {
                    required: true,
                    min: 0,
                    decimal: {
                    integer: 12,
                    fraction: ${setting.priceScale}
                }
                },
                    maximumPrice: {
                    required: true,
                    min: 0,
                    decimal: {
                    integer: 12,
                    fraction: ${setting.priceScale}
                },
                    compare: "#minimumPrice"
                },
                    order: "digits",
                    beginDate: "required",
                    endDate:"required",
                    isUsed: {
                    remote: {
                    url: "checkUsing.action?type=freeShipping",
                    cache: false
                }
                }
                },
                    messages: {
                    isUsed: {
                    remote: "（不能同时进行同种类型的促销）"
                }
                }
                });

                });
    </script>
</head>
<body>
<div class="path">
    <a href="${base}/asl-admin/common/index.htm">${message("admin.path.index")}</a> &raquo; ${message("admin.promotion.add")}
</div>
<form id="inputForm" action="save.htm" method="post">
    <ul id="tab" class="tab">
        <li>
            <input type="button" value="${message("admin.promotion.base")}" />
        </li>
	[#--<li>
        <input type="button" value="${message("Promotion.introduction")}" />
    </li>--]
    </ul>
    <div class="tabContent">
        <table class="input">
            <tr>
                <th>
                    促销类型
                </th>
                <td>
                    <input type="hidden" name="type" value="freeShipping" />
                    包邮
                </td>
            </tr>
            <tr>
                <th>
                    <span class="requiredField">*</span>${message("Promotion.name")}:
                </th>
                <td colspan="2">
                    <input type="text" name="name" class="text" maxlength="200" />
                </td>
            </tr>
            <tr>
                <th>
                    <span class="requiredField">*</span>${message("Promotion.title")}:
                </th>
                <td colspan="2">
                    <input type="text" name="title" class="text" maxlength="200" /> （显示在app:全场满199包邮费）
                </td>
            </tr>
            <tr>
                <th>
				${message("Promotion.beginDate")}:
                </th>
                <td colspan="2">
                    <input type="text" id="beginDate" name="beginDate" class="text Wdate" value="" onfocus="WdatePicker({dateFmt: 'yyyy-MM-dd HH:mm:ss', maxDate: '#F{$dp.$D(\'endDate\')}'});" />
                </td>
            </tr>
            <tr>
                <th>
				${message("Promotion.endDate")}:
                </th>
                <td colspan="2">
                    <input type="text" id="endDate" name="endDate" class="text Wdate" value="" onfocus="WdatePicker({dateFmt: 'yyyy-MM-dd HH:mm:ss', minDate: '#F{$dp.$D(\'beginDate\')}'});" />
                </td>
            </tr>
            <tr>
                <th>
                    <span class="requiredField">*</span>购物车最低价:
                </th>
                <td colspan="2">
                    <input type="text" id="minimumPrice" name="minimumPrice" class="text" maxlength="16" />
                </td>
            </tr>
		[#--
        <tr>
            <th>
                <span class="requiredField">*</span>${message("Promotion.maximumPrice")}:
            </th>
            <td colspan="2">
                <input type="text" name="maximumPrice" class="text" maxlength="16" />
            </td>
        </tr>
        <tr>
            <th>
                优惠价格(减):
            </th>
            <td>
                <input type="text" name="cut" class="text" maxlength="200" />(促销类型为满减时请填写)
            </td>
        </tr>
        --]
            <tr>
                <th>
				${message("admin.common.order")}:
                </th>
                <td>
                    <input type="text" name="order" class="text" maxlength="9" />
                </td>
            </tr>
            <tr>
                <th>
                    设置 :
                </th>
                <td>
                    <label>
                        <input type="checkbox" name="isCouponAllowed" value="true" />能否使用优惠券
                        <input type="hidden" name="_isCouponAllowed" value="false" />
                    </label>
                    <label>
                        <input type="checkbox" name="isUsed" value="true" />是否启动促销
                        <input type="hidden" name="_isUsed" value="false" />
                    </label>
                </td>
            </tr>
            <tr class="productCategory">
                <th>
				${message("Promotion.productCategories")}
                </th>
                <td colspan="2">
				[#list productCategories as productCategory]
                    <label>
                        <input type="checkbox" name="productCategoryIds" value="${productCategory.id}" />${productCategory.name}
                    </label>
				[/#list]
                </td>
            </tr>
        </table>
        <table id="productTable" class="input">
            <tr>
                <th>
				${message("Promotion.products")}:
                </th>
                <td colspan="2">
                    <input type="text" id="productSelect" name="productSelect" class="text" maxlength="200" title="${message("admin.promotion.productSelectTitle")}" />
                </td>
            </tr>
            <tr id="productTitle" class="title hidden">
                <th>
                    &nbsp;
                </th>
                <td width="712">
				${message("Product.name")}
                </td>
                <td>
				${message("admin.common.handle")}
                </td>
            </tr>
        </table>
	[#--
    <table id="giftTable" class="input">
        <tr>
            <th>
                ${message("Promotion.giftItems")}:
            </th>
            <td colspan="3">
                <input type="text" id="giftSelect" name="giftSelect" class="text" maxlength="200" title="${message("admin.promotion.giftSelectTitle")}" />
            </td>
        </tr>
        <tr id="giftTitle" class="title hidden">
            <th>
                &nbsp;
            </th>
            <td width="500">
                ${message("Product.name")}
            </td>
            <td width="200">
                ${message("GiftItem.quantity")}
            </td>
            <td>
                ${message("admin.common.handle")}
            </td>
        </tr>
    </table>
    --]
    </div>
    <div class="tabContent">
        <table class="input">
            <tr>
                <td>
                    <textarea id="editor" name="introduction" class="editor" style="width: 100%;"></textarea>
                </td>
            </tr>
        </table>
    </div>
    <table class="input">
        <tr>
            <th>
                &nbsp;
            </th>
            <td>
                <input type="submit" class="button" value="${message("admin.common.submit")}" />
                <input type="button" class="button" value="${message("admin.common.back")}" onclick="location.href='list.htm'" />
            </td>
        </tr>
    </table>
</form>
</body>
</html>